import React from 'react'
import { connect } from 'dva'
import { Card,Spin} from 'antd'
import moment from 'moment'

/**
 * RealisationList 
 */
import TableList from '../../../components/TableList'
class RealisationList extends React.Component {
    state = {
        data: this.props.realisationList,
    }
    componentDidMount() {
        this.fetchData(this.props)
    }
    componentWillReceiveProps(nextProps) {

        if ((nextProps.lPortId !== this.props.lPortId) || (nextProps.date !== this.props.date)) {
            this.fetchData(nextProps)
        }
        if (nextProps.realisationList !== this.props.realisationList) {
            this.setState({
                data: nextProps.realisationList,
            })
        }
    }
    fetchData = (props) => {
        this.setState({
            data:{}
        })
        props.dispatch({
            type: 'combinatorialAnalysis/getRealisationList',
            payload:props
        })
    }
    render() {
        return(
            <Card className="tableCard realisationList">
                {
                Object.keys(this.state.data).length?<TableList fieldList={this.state.data.field} list={this.state.data.list} rowKey='code' pagination={this.state.data.list.length>10?{ size:"small"}:false} />:<Spin />
                }
            </Card>
        )

    }
}

RealisationList.defaultProps = {
    lPortId: null,
    date: null,
    realisationList: {
        // "field": [{
        //     "id": "code",
        //     "name": "股票代码"
        // },
        // {
        //     "id": "name",
        //     "name": "股票简称"
        // },
        // {
        //     "id": "days",
        //     "name": "持仓天数"
        // },
        // {
        //     "id": "weight",
        //     "name": "平均持股权重"
        // },
        // {
        //     "id": "ratio",
        //     "name": "收益贡献占比"
        // }],
        // "list": [{
        //     "id":"1",
        //     "code": "600000-CN",
        //     "name": "浦发银行",
        //     "days": 270,
        //     "weight": 0.1178,
        //     "ratio": 6.33
        // }]
    }
}

export default connect()(RealisationList)
